Re: [GENERAL] The value returned by autoinc ?

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема Re: [GENERAL] The value returned by autoinc ?
Дата
Msg-id l03110702b31288079b29@[147.233.159.109]
обсуждение исходный текст
Ответ на The value returned by autoinc ?  (Silvio Emanuel Barbosa de Macedo <smacedo@inescn.pt>)
Ответы Re: [GENERAL] The value returned by autoinc ?  (Silvio Emanuel Barbosa de Macedo <smacedo@inescn.pt>)
Список pgsql-general
At 2:57 +0200 on 15/3/99, Silvio Emanuel Barbosa de Macedo wrote:


> When I insert data into a table with a sequence associated to a column
> (and the required trigger), how can I know the value the sequence has
> just generated ? (think in parallel accesses)
>
> Would this approach be the answer ?
> begin work
>     insert...
>     select max...
> commit

No, this approach is a waste of precious time... The correct approach is:

   INSERT...
   SELECT currval( 'seq_name' );

currval gives you the last value the sequence has given to the current
session. That is, it won't work if you use it before the insertion (because
the sequence didn't give you a number yet). It will also give you the
correct number even if between the INSERT and the SELECT, another process
or another connection also made an insert.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



В списке pgsql-general по дате отправления:

Предыдущее
От: "Bernhard Krick"
Дата:
Сообщение: how to start postmaster at system boot on linux?
Следующее
От: Silvio Emanuel Barbosa de Macedo
Дата:
Сообщение: Re: [GENERAL] The value returned by autoinc ?